﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections.ObjectModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace MLY
{
  internal static class ExtensionMethods
  {
    internal static void RedirectTo(this HttpResponse response, string url)
    {
      response.Redirect(url);
    }

    internal static void RedirectTo(this HttpResponse response, 
                                    string url, bool endResponse)
    {
      response.Redirect(url, endResponse);
    }

    public static bool Include(this string text, string subString)
    {
      if (string.IsNullOrEmpty(subString) || string.IsNullOrEmpty(text)) 
        return false; 
      return text.IndexOf(subString, StringComparison.InvariantCultureIgnoreCase) >= 0;
    }

    internal static void SetValueToNull(this FormViewInsertEventArgs e, string key)
    {
      if (e.Values[key] != null && e.Values[key].ToString() == "")
        e.Values[key] = null;
    }

    internal static void SetValueToNull(this FormViewUpdateEventArgs e, string key)
    {
      if (e.NewValues[key] != null && e.NewValues[key].ToString() == "")
        e.NewValues[key] = null;
    }

    //internal static ReadOnlyCollection<MetaDataMember> ColumnNames<TEntity>(this DataContext source)
    //{
    //  return source.Mapping.MappingSource.GetModel(typeof(DataContext)).GetMetaType(typeof(TEntity)).DataMembers;
    //}

  }

}